/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.ruby_string.delayed;

import moved.org.objectweb.asm.MethodVisitor;
import picounit.Should;
import picounit.Test;
import picounit.Verify;

public class DefaultInstructionsTest implements Test {
	private final DefaultMethodInstructions defaultInstructions;

	private final Collaborators collaborators;

	private final Should should;
	private final Verify verify;

	interface Collaborators {
		MethodVisitor methodVisitor();
		MethodInstruction firstMethodInstruction();
		MethodInstruction secondMethodInstruction();
		MethodInstruction thirdMethodInstruction();
		MethodInstruction fourthMethodInstruction();
	}
	
	public DefaultInstructionsTest(Collaborators collaborators, Should should, Verify verify) {
		this.defaultInstructions = new DefaultMethodInstructions();
		
		this.collaborators = collaborators;

		this.should = should;
		this.verify = verify;
	}
	
	public void shouldReplayBackAllAddedInstructionsAgainstAMethodVisitor() {
		collaborators.firstMethodInstruction().accept(collaborators.methodVisitor());
		collaborators.secondMethodInstruction().accept(collaborators.methodVisitor());
		collaborators.thirdMethodInstruction().accept(collaborators.methodVisitor());
		collaborators.fourthMethodInstruction().accept(collaborators.methodVisitor());

		should.expectAboveWhenTheFollowingOccurs();

		defaultInstructions.add(collaborators.firstMethodInstruction());
		defaultInstructions.add(collaborators.secondMethodInstruction());
		defaultInstructions.add(collaborators.thirdMethodInstruction());
		MethodInstructions instructions = defaultInstructions.add(collaborators.fourthMethodInstruction());

		defaultInstructions.accept(collaborators.methodVisitor());

		verify.that(instructions).isTheSameAs(defaultInstructions);
	}
}
